package com.ling.service;

import com.ling.bean.Area;
import com.ling.bean.AreaExample;
import com.ling.dao.AreaMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AreaService {

    private final AreaMapper areaMapper;

    @Autowired
    public AreaService(AreaMapper areaMapper) {
        this.areaMapper = areaMapper;
    }


    //保存领域
    public void saveArea(Area area) {
        areaMapper.insertSelective(area);
    }

    //查询领域,按照名字顺序排序
    public List<Area> getArea() {
        //按照领域的名称顺序获取
        AreaExample areaExample = new AreaExample();
        areaExample.setOrderByClause("areaname ASC");
        return areaMapper.selectByExample(areaExample);
    }

    //修改领域
    public void updateArea(Area area) {
        areaMapper.updateByPrimaryKeySelective(area);
    }

    //删除指定id的领域
    public void delArea(String id) {
        areaMapper.deleteByPrimaryKey(id);
    }

    //查询指定id的领域
    public Area getArea(String id) {
        return areaMapper.selectByPrimaryKey(id);
    }
}
